package main

import (
	"go.uber.org/zap"
	"log"
	"time"
	"xin/raft"
	"xin/raft/pb"
)

// 无法直接测试
// transport_tcp.go 收到请求并非直接返回；有raft算法层的逻辑在。

func main() {
	logger, err := zap.NewDevelopment()
	if err != nil {
		log.Panic(err)
	}

	defer logger.Sync()

	transport := raft.NewTcpTransport(1235, logger)

	// 仅仅测试 TCP 以及 Protobuf 序列化问题无需 init
	//err = transport.Init()
	//if err != nil {
	//	log.Panic(err)
	//}

	vote := &pb.RequestVote{
		Term:         999,
		CandidateId:  uint64(999),
		LastLogIndex: 999,
		LastLogTerm:  999,
	}

	endpoint := raft.Endpoint("127.0.0.1:1234")

	resp := &pb.RequestVoteResp{}

	err = transport.RequestVote(vote, endpoint, resp)
	if err != nil {
		log.Panic(err)
	}

	time.Sleep(2 * time.Second)
}
